package com.cy.pj.arithmetic.controller;

import com.cy.pj.arithmetic.service.ArithmeticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Cx
 * @stage secondStageOfWeb
 * @creat 2020-11-09 14:12
 */
@Controller
public class ArithmeticController {

    @Autowired
    private ArithmeticService arithmeticService;

    @ResponseBody
    @RequestMapping("/doCompute/{n1}/{n2}")
    public String doCompute(@PathVariable Integer n1, @PathVariable Integer n2) {
        Integer result = n1 / n2;
        return "the result is" + " : " + "[ " + result + " ]";
    }

    @ResponseBody
    @RequestMapping("/doSum/{nums}")
    public String doSum(@PathVariable Integer... nums) {
        return "the result is" + arithmeticService.doSum(nums);
    }

    @ResponseBody
    @RequestMapping("/Sum/{a}/{b}")
    public String doSum(@PathVariable Integer a, @PathVariable Integer b) {
        return "the result is" + arithmeticService.sum(a, b);
    }

}
